package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysInst;
import com.ruoyi.system.service.ISysInstService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 机构Controller
 * 
 * @author ruoyi
 * @date 2025-03-08
 */
@RestController
@RequestMapping("/system/inst")
public class SysInstController extends BaseController
{
    @Autowired
    private ISysInstService sysInstService;

    /**
     * 查询机构列表
     */
    @PreAuthorize("@ss.hasPermi('system:inst:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysInst sysInst)
    {
        startPage();
        List<SysInst> list = sysInstService.selectSysInstList(sysInst);
        return getDataTable(list);
    }

    /**
     * 导出机构列表
     */
    @PreAuthorize("@ss.hasPermi('system:inst:export')")
    @Log(title = "机构", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysInst sysInst)
    {
        List<SysInst> list = sysInstService.selectSysInstList(sysInst);
        ExcelUtil<SysInst> util = new ExcelUtil<SysInst>(SysInst.class);
        util.exportExcel(response, list, "机构数据");
    }

    /**
     * 获取机构详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:inst:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysInstService.selectSysInstById(id));
    }

    /**
     * 新增机构
     */
    @PreAuthorize("@ss.hasPermi('system:inst:add')")
    @Log(title = "机构", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysInst sysInst)
    {
        return toAjax(sysInstService.insertSysInst(sysInst));
    }

    /**
     * 修改机构
     */
    @PreAuthorize("@ss.hasPermi('system:inst:edit')")
    @Log(title = "机构", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysInst sysInst)
    {
        return toAjax(sysInstService.updateSysInst(sysInst));
    }

    /**
     * 删除机构
     */
    @PreAuthorize("@ss.hasPermi('system:inst:remove')")
    @Log(title = "机构", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysInstService.deleteSysInstByIds(ids));
    }
}
